package com.jhhc.Http.Service;


import com.jhhc.RHDB.Data.Dao.ST_PPTN_R5Mapper;
import com.jhhc.RHDB.Data.Dao.ST_RIVER_R5Mapper;
import com.jhhc.RHDB.Data.Dao.ST_RSVR_R5Mapper;
import com.jhhc.RHDB.Data.Pojo.ST_PPTN_R;
import com.jhhc.RHDB.Data.Pojo.ST_RIVER_R;
import com.jhhc.RHDB.Data.Pojo.ST_RSVR_R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InsertHxDataService {

    @Autowired
    private  ST_RSVR_R5Mapper st_rsvr_r5Mapper;
    @Autowired
    private  ST_PPTN_R5Mapper st_pptn_r5Mapper;
    @Autowired
    private ST_RIVER_R5Mapper st_river_r5Mapper;

    //雨量
    public int insertHxPPTNData(List<ST_PPTN_R> list){
        int num = 0;//insert插入总数量
        int count = 0;//insert插入数量
        int batchCount = 190;//每批commit的个数
        int batchLastIndex = batchCount - 1;// 每批最后一个的下标
        for (int index = 0; index < list.size() -1;) {
            if(batchLastIndex > list.size() - 1){
                batchLastIndex = list.size() - 1;

                count = st_pptn_r5Mapper.insertHxPPTNData(list.subList(index,batchLastIndex + 1));

                num+=count;
                break;
            }else {
                count = st_pptn_r5Mapper.insertHxPPTNData(list.subList(index,batchLastIndex + 1));
                index = batchLastIndex + 1;
                batchLastIndex = index + (batchCount - 1);

            }
            num+=count;
        }
        return num;
    }

    //河道
    public int insertHxRIVERData(List<ST_RIVER_R> list){
        int num = 0;//insert插入总数量
        int count = 0;//insert插入数量
        int batchCount = 190;//每批commit的个数
        int batchLastIndex = batchCount - 1;// 每批最后一个的下标
        for (int index = 0; index < list.size() -1;) {
            if(batchLastIndex > list.size() - 1){
                batchLastIndex = list.size() - 1;
                count = st_river_r5Mapper.insertHxRIVERData(list.subList(index,batchLastIndex + 1));

                num+=count;
                break;
            }else {
                count = st_river_r5Mapper.insertHxRIVERData(list.subList(index,batchLastIndex + 1));
                index = batchLastIndex + 1;
                batchLastIndex = index + (batchCount - 1);

            }
            num+=count;
        }
        return num;
    }


    //水库
    public int insertHxReservoirData(List<ST_RSVR_R> list){
        int num = 0;//insert插入总数量
        int count = 0;//insert插入数量
        int batchCount = 190;//每批commit的个数
        int batchLastIndex = batchCount - 1;// 每批最后一个的下标
        for (int index = 0; index < list.size() -1;) {
            if(batchLastIndex > list.size() - 1){
                batchLastIndex = list.size() - 1;
                count = st_rsvr_r5Mapper.insertHxReservoirData(list.subList(index,batchLastIndex + 1));

                num+=count;
                break;
            }else {
                count = st_rsvr_r5Mapper.insertHxReservoirData(list.subList(index,batchLastIndex + 1));
                index = batchLastIndex + 1;
                batchLastIndex = index + (batchCount - 1);

            }
            num+=count;
        }
        return num;
    }




    //删除


}
